package leetcode.code1968;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] rearrangeArray(int[] nums) {
		Arrays.sort(nums);
		int len = nums.length;
		int[] ans = new int[len];
		int r = len - (len >> 1);
		for (int i = 0, j = r, p = 0; i < r; i++, j++) {
			ans[p++] = nums[i];
			if (p < len) {
				ans[p++] = nums[j];
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		this.rearrangeArray(H.str2array3("[1,2,3,4,5]"));
		this.rearrangeArray(H.str2array3("[1,5,2,6,3,7,4,8]"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
